home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol086 / roff43.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-12-15  |  4.7 KB  |  213 lines

  1. /********************************************************/
  2. /*                            */
  3. /*            ROFF4, Version 1.60            */
  4. /*                            */
  5. /*(C) 1983,4 by Ernest E. Bergmann            */
  6. /*        Physics, Building #16            */
  7. /*        Lehigh Univerisity            */
  8. /*        Bethlehem, Pa. 18015            */
  9. /*                            */
  10. /* Permission is hereby granted for all commercial and    */
  11. /* non-commercial reproduction and distribution of this    */
  12. /* material provided this notice is included.        */
  13. /*                            */
  14. /********************************************************/
  15. /*MAR 10, 1984*/
  16. /********************************************************/
  17. /* March 1984  DeSmet C version */
  18. /* Henry Harpending*/
  19. /* Anthropology Department*/
  20. /* University of New Mexico*/
  21. /* Albuquerque, NM  87131*/
  22. /*   no restrictions */
  23. /*********************************************************/
  24. #include "a:roff4.h"
  25. /****************************************/
  26. regist(s)    /*checks RLIST; creates new entry if needed;
  27.         returns pointer to integer variable*/
  28. char *s;
  29. {int *pw;
  30. char *pc,*s2;
  31. pw=find2(s,RLINK);
  32. if(pw) return(pw); /*else create new entry*/
  33. pw=TREND;
  34. *pw=RLINK;
  35. pc=pw+1;
  36. s2=s;
  37. transfer(&s2,&pc,'\0');
  38. RLINK=TREND;
  39. pw=pc;
  40. *pw=REGDEF;
  41. TREND=pw+1;
  42. return(pw);
  43. }
  44. /****************************************/
  45. dovar()    /*process .RG request*/
  46. {char typ, wbuf[MAXLINE];
  47. int val, *pw;
  48. getwrd(LINE,wbuf);
  49. skip_blanks(LINE);
  50. val=get_val(LINE,&typ);
  51. getwrd(LINE,wbuf);
  52. if(wbuf[0]==NUMSIGN && wbuf[1]=='\0')
  53.     {set(&NEWPAG,val,typ,NEWPAG,1,9999);
  54.     }
  55. else    {pw=regist(wbuf);
  56.     set(pw,val,typ,REGDEF,1,9999);
  57.     }
  58. }
  59. /****************************************/
  60. dodiv()        /*process .DIversion*/
  61. {char wbuf[MAXLINE],*pc,*pc1,*wb;
  62. struct divfd *pd;
  63. int *pw;
  64. getwrd(LINE,wbuf);
  65. if(getwrd(LINE,wbuf)!=WE_HAVE_A_WORD)
  66.     {strcpy(wbuf,"JUNK.$$$");
  67.     fprintf(stderr,"DIVERSION has no name, %s assumed\n",
  68.                 wbuf);
  69.     }
  70. ucstr(wbuf);
  71. if(pd=find2(wbuf,DLINK)){    /*if in table*/
  72.     if(!(pd->bf)){        /*if not open*/
  73.         if( ((pd->bf) = fopen(wbuf,"w")) == ERROR){
  74.                  printf("Error on open <%s>\n",wbuf);
  75.                exit();
  76.          }
  77.      }
  78. }
  79. else    /*not in table*/
  80.     {pw=TREND;
  81.     *pw=DLINK;
  82.     pc1=pc=pw+1;
  83.     wb=wbuf;
  84.     transfer(&wb,&pc,'\0');
  85.     DLINK=TREND;
  86.     pd=pc;
  87.     TREND = pd+1;
  88.     pd->nm = pc1;
  89.     pd->ls = pd->cs = 0;
  90.     if( ((pd->bf) = fopen(wbuf,"w")) == ERROR){
  91.             printf("Can't open <%s>\n",wbuf);
  92.             exit();
  93.             }
  94.     }
  95.  
  96. while(fgets2(LINE,ifp))
  97.     {if((*LINE==COMMAND)&&(comtyp(LINE)==ED)) break;
  98.     if(pc=macq(LINE))
  99.         {pbstr(pc);
  100.         continue;
  101.         }
  102.     /*else*/
  103.     fputs(LINE,pd->bf);
  104.     (pd->ls)++;
  105.     (pd->cs) += 1+strlen(LINE);/*crlf=2*/
  106.     }
  107. }
  108. /****************************************/
  109. source()
  110. {struct divfd *pd;
  111. char name[MAXLINE];
  112. getwrd(LINE,name);
  113. if(getwrd(LINE,name)!=WE_HAVE_A_WORD)
  114.     {fprintf(stderr,".SO has no name\n");
  115.     return;
  116.     }
  117. ucstr(name);
  118. if(pd=find2(name,DLINK)) dclose(pd);
  119. if(FPTR<FMAX) FSTACK[FPTR++]=ifp;
  120. else    {fprintf(stderr,"FSTACK overflow\n");
  121.     exit();
  122.     }
  123. if( (ifp=fopen(name,"r")) != ERROR ) return;
  124.     /*else*/
  125.     fprintf(stderr,"Can't open <%s>\n",name);
  126. endso();
  127. }
  128. /****************************************/
  129. showr()    /*lists register names and contents*/
  130. {int *pw, *pr;
  131. char *pc;
  132. fprintf(stderr,"REGISTERS and <values>:\n");
  133. pw=RLINK;
  134. while(pw)
  135.     {pc=pw+1;
  136.     fprintf(stderr,"%s ",pc);
  137.     pr=pc+1+strlen(pc);
  138.     fprintf(stderr,"<%d>\n",*pr);
  139.     pw=*pw;
  140.     }
  141. dashes();
  142. }
  143. /****************************************/
  144. showd()    /*shows all diversions and status*/
  145. {int *pw;
  146. char *pc;
  147. struct divfd *pd;
  148.  
  149. fprintf(stderr, "Diversion files:\n");
  150. pw=DLINK;
  151. while(pw)
  152.     {pc=pw+1;
  153.     fprintf(stderr,"%s: ",pc);
  154.     pd=pc+1+strlen(pc);
  155.     fprintf(stderr,"%d characters, %d lines [",
  156.             pd->cs, pd->ls );
  157.     if(pd->bf) fprintf(stderr,"open]\n");
  158.     else    fprintf(stderr,"closed]\n");
  159.     pw =*pw;
  160.     }
  161. dashes();
  162. }
  163. /****************************************/
  164. dsclose()    /*flushes and closes all open diversions*/
  165. {int *pw;
  166. char *pc;
  167. struct divfd *pd;
  168.  
  169. pw = DLINK;
  170. while(pw)
  171.     {pc=pw+1;
  172.      pd=pc+1+strlen(pc);
  173.     if(pd->bf) dclose(pd);
  174.     pw=*pw;
  175.     }
  176. }
  177. /****************************************/
  178. dclose(pd)    /*flushes and closes diversion*/
  179. struct divfd *pd;
  180. {if(pd&&(!(pd->bf))) return(FALSE);
  181. fprintf(stderr,"closing %s\n ",pd->nm);
  182. putc('\n',pd->bf);
  183. putc(CPMEOF,pd->bf);
  184. putc('\n',pd->bf);
  185. if( (fclose(pd->bf)) ==ERR)
  186.     fprintf(stderr,"****bad close****\n");
  187. else    {fprintf(stderr,"[O.K.]\n");
  188.  
  189.     pd->bf = FALSE;
  190.     }
  191. return(TRUE);
  192. }
  193. /****************************************/
  194. ucstr(s)    /*convert s to upper case*/
  195. char *s;
  196. {while(*s)
  197.     {*s = toupper(*s);
  198.     s++;
  199.     }
  200. }
  201. /****************************************/
  202. endso()    /*called upon EOF to return to previous input file*/
  203. {if(FPTR)
  204.     {close(ifp);
  205.     ifp=FSTACK[--FPTR];
  206.     }
  207. BINP=0;
  208. }
  209. /****************************************/
  210. dashes()
  211. {fprintf(stderr,"-----------\n");
  212. }
  213.